package com.tengju.bff.infrastructure.export.convert;

import com.tengju.bff.interfaces.covercharge.constant.InvoiceEnum;
import com.tengju.bff.interfaces.covercharge.constant.SelfWithdrawStatusEnum;
import com.tengju.bff.interfaces.covercharge.entity.vo.AdminSelfCertificationQueryVo;
import com.tengju.export.domain.record.Table;
import com.tengju.motivation.domain.shared.DateUtil;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author: 李大仙
 * @date: 2021/8/26 8:40 下午
 */
public class BillApplyRecordConvert {
    public static Table convert(List<AdminSelfCertificationQueryVo> records) {
        Table table = new Table();
        table.setHeader(buildHeader());
        table.setRecords(buildRecords(records));
        return table;
    }

    private static List<List<String>> buildRecords(List<AdminSelfCertificationQueryVo> records) {
        List<List<String>> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(records)){
            return result;
        }
        int index = 1;
        for (AdminSelfCertificationQueryVo adminSelfCertificationQueryVo : records) {
            List<String> row = new ArrayList<>();
            row.add(String.valueOf(index));
            row.add(String.valueOf(adminSelfCertificationQueryVo.getIdCode()));
            row.add(adminSelfCertificationQueryVo.getName());
            row.add(adminSelfCertificationQueryVo.getMobile());
            row.add(adminSelfCertificationQueryVo.getCompanyName());
            row.add(adminSelfCertificationQueryVo.getCompanyNo());
            row.add(adminSelfCertificationQueryVo.getIdcardName());
            row.add(adminSelfCertificationQueryVo.getBankNo());
            row.add(adminSelfCertificationQueryVo.getBankName());
            row.add(adminSelfCertificationQueryVo.getMoney().toString());
            row.add(Optional.ofNullable(InvoiceEnum.getInvoiceDesc(adminSelfCertificationQueryVo.getInvoice())).map(InvoiceEnum::getDesc).orElse(""));
            row.add(DateUtil.format(adminSelfCertificationQueryVo.getCreatedAt()));
            row.add(Optional.ofNullable(SelfWithdrawStatusEnum.getStatusDesc(adminSelfCertificationQueryVo.getStatus())).map(SelfWithdrawStatusEnum::getDesc).orElse(""));
            row.add(DateUtil.format(adminSelfCertificationQueryVo.getUpdatedAt()));
            row.add(adminSelfCertificationQueryVo.getQueryRemark());
            row.add(adminSelfCertificationQueryVo.getIssuingNote());
            row.add(adminSelfCertificationQueryVo.getChannel());
            result.add(row);
            index++;
        }
        return result;
    }

    private static List<String> buildHeader() {
        List<String> headerList = new ArrayList<>();
        headerList.add("序号");
        headerList.add("代理id");
        headerList.add("代理姓名");
        headerList.add("手机号");
        headerList.add("企业/个体户名称");
        headerList.add("社会信用代码/税号");
        headerList.add("户名");
        headerList.add("银行卡号");
        headerList.add("开户行");
        headerList.add("申请金额");
        headerList.add("发票类型");
        headerList.add("申请时间");
        headerList.add("状态");
        headerList.add("更新时间");
        headerList.add("渠道返回信息");
        headerList.add("发放备注");
        headerList.add("账户类型");
        return headerList;
    }
}
